﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;
using Workflows.Components.Reports.Properties;

namespace Workflows.Components.Reports
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class SetManipulationComponent:WorkflowComponentBase
	{
		#region ctor
		/// <summary>
		/// 
		/// </summary>
		public SetManipulationComponent()
			: base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.Report_Tasks.ToString();
			this.ComponentName = "Set Manipulation";
			this.Description = "manipulate set data";
			this.ComponentIcon = Resources.data_source;
			this.ComponentImage = Resources.free;

			this._Instruction =
				new SetManipulationInstruction(this.ComponentID, Guid.Empty,
					new Dictionary<string, SetDataProvider>(), 
					new List<SetJoin>(), new List<SetOperation>(), 
					new List<string>(), 
					string.Empty);
			this._Output = new SetManipulationOutput(this.ComponentID, Guid.Empty, string.Empty);
		}
		#endregion

		#region Overrides of WorkflowComponentBase

		private SetManipulationInstruction _Instruction;
		/// <summary>an object that encapsulate instruction settings.</summary>
		public override InstructionBase Instruction
		{
			get { return _Instruction; }
			set { _Instruction = (SetManipulationInstruction)value; }
		}

		private SetManipulationOutput _Output;
		/// <summary>an object to encapsulate output</summary>
		public override ResultBase Output
		{
			get { return _Output; }
			set { _Output=(SetManipulationOutput)value; }
		}

		#endregion

		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
			this.Instruction.Serialize(ref xDoc, ref xNode);
			return xNode;
		}

		public override WorkflowComponentBase Instantiate(XmlNode xNode)
		{
			SetManipulationComponent component = (SetManipulationComponent)base.Instantiate(xNode);
			component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
			return component;
		}
	}
}
